#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <sys/time.h>

/*
 * 根据本地时间取得目前的UTC时间
 */

void gmtime_test()
{
  char * wday[] = {"Sun", "Mon", "Tue", "Wed", "Thr", "Fri", "Sat"};
  time_t timep;
  struct tm * ptm;

  time(&timep);
  ptm = gmtime(&timep);

  printf("%d-%d-%d ", (1990 + ptm->tm_year), (1 + ptm->tm_mon), ptm->tm_mday);
  printf("%s %d:%d:%d\n",wday[ptm->tm_wday], ptm->tm_hour, ptm->tm_min, ptm->tm_sec);
}

void gmtime_test2()
{
  char * wday[] = {"Sun", "Mon", "Tue", "Wed", "Thr", "Fri", "Sat"};
  time_t timep;
  struct tm * ptm;

	timep = 315532800 * 10 + 457422;
  ptm = gmtime(&timep);

  printf("%d-%d-%d ", (1990 + ptm->tm_year), (1 + ptm->tm_mon), ptm->tm_mday);
  printf("%s %d:%d:%d\n",wday[ptm->tm_wday], ptm->tm_hour, ptm->tm_min, ptm->tm_sec);
}

void main()
{
  gmtime_test();

  gmtime_test2();
}
